
class V2XManager:
    """
    V2X Manager for platooning, cooperative perception and so on.

    Parameters
    ----------
    cav_world : simulation world object
        CAV world.
    Attributes
    ----------

    cav_nearby : dict
        The dictionary that contains the cavs in the communication range.

    """

    def __init__(self, vehicle_id, cav_world):
        self.vehicle_id = vehicle_id
        self.communication_range = 300
        self.cav_world = cav_world

        # found CAVs nearby
        self.nearby_cav_id = set()
        self.nearby_cav_data = dict()

    def update_info(self):
        """
        Update all communication plugins with current localization info.
        """
        self.search()

    def search(self):
        """
        Search the CAVs nearby.
        """
        self.nearby_cav_data = self.cav_world.get_nearby_cav_data(self.vehicle_id, self.communication_range)

    def get_nearby_cav(self):
        return self.nearby_cav_data

    def request_join(self, vehicle_id, pid):
        self.cav_world.request_join(vehicle_id, pid)
